﻿using System;
using System.Collections.Generic;

namespace RedisDemos.Extensions
{
    public static class DateTimeExtensions
    {
        public static IEnumerable<DateTime> Days(this DateTime date)
        {
            var current = date.FirstDayOfMonth();
            var end = date.LastDayOfMonth();
            while ((current = current.AddDays(1)) <= end)
                yield return current;
        }

        public static DateTime FirstDayOfMonth(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, 1);
        }

        public static DateTime LastDayOfMonth(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month), 23, 59, 59);
        }
    }
}
